<?php
namespace EasyPhpWeb;

class RequestBody{
    private $type = "";
    private $bodyStr = "";
    public function __construct($type, $bodyStr)
    {
        $this->type = $type;
        $this->bodyStr = $bodyStr;
    }

    public function getBody(){
        $body = null;
        switch($this->type){
            case "application/x-www-form-urlencoded": 
                parse_str($this->bodyStr, $body);
                break;
            case "application/json": 
                $body = json_decode($this->bodyStr, true);
                break;
            case "mutipart/form-data":
                //todo
                break;
            default:
                $body = $this->bodyStr;
        }
        return $body;
    }
}